﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  
</head>

<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>

  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content report">

    <div class="panel panel-default x-panel x-panel-layout">

      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/report">报表</a></li>
          <li class="active">访客报表</li>
        </ol>
      </div>

      <div class="panel-body">

        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">

          <div class="x-breadcrumb-wrapper">
          
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>报表&nbsp;-&nbsp;访客报表</span></h2>
              <div class="pull-right">
                <c:choose>
                  <c:when test="${not empty currentPrincipal.site}">
                    <span class="current-branchCode">${currentPrincipal.site.name}</span>
                  </c:when>
                  <c:otherwise>
                    <select name="site">
                      <option value="">所有门店</option>
                      <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                        <option value="${site.id}" ${site.id == selectSite.id ? 'selected' : ''}>${site.name}</option>
                      </c:forEach>
                    </select>
                  </c:otherwise>
                </c:choose>
              </div>
            </div>
            
            <div class="x-breadcrumb-wrapper top-margin-20" style="position: relative;">
              <fmt:formatDate value="${currentDate}" pattern="yyyy-MM-dd" var="day" />
              <ul class="nav nav-pills x-breadcrumb-nav">
                <li class="pull-left ${period eq 'day' ? 'active' : ''}"><a href="${ctx.host}/visitor-reports?site=${selectSite.id}&date=${day}&period=day">日</a></li>
                <li class="pull-left ${period eq 'week' ? 'active' : ''}"><a href="${ctx.host}/visitor-reports?site=${selectSite.id}&date=${day}&period=week">周</a></li>
                <li class="pull-left ${period eq 'month' ? 'active' : ''}"><a href="${ctx.host}/visitor-reports?site=${selectSite.id}&date=${day}&period=month">月</a></li>
                <div class="pull-right" style="margin-left:15px;">
                  <input type="text" class="form-control date" name="date" value="${day}" data-validate = "required" placeholder="请选择日期" readOnly/>
                </div>
                <a href="${ctx.host}/visitor-reports/export-view" data-target="#report-export" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default pull-right">导出</a>
              </ul>
            </div>
            
          </div>
          
          <div class="tab-content">
            <div class="tab-pane fade active in"style="min-height: 100px;">
              <c:if test="${(currentPrincipal.admin or currentPrincipal.root) and empty selectSite}">
               <h2 class="title">
                 <i class="glyphicon glyphicon-triangle-right" style="color: #FF8100;" title=""></i>&nbsp;&nbsp;<span>总访客数据</span>
                 <c:choose>
                   <c:when test="${period == 'day'}">
                     <p class="form-control-statis pull-right">日期：${day}</p>
                   </c:when>
                   <c:otherwise>
                     <p class="form-control-statis pull-right">日期：${startDate}&nbsp;&nbsp;-&nbsp;&nbsp;${endDate}</p>
                   </c:otherwise>
                 </c:choose>
               </h2>
               
               <div style="margin: 0 15px;">
                <div class="x-breadcrumb-content row key-data">
                  <div class="col-xs-4">
                    <h1>${persist.visitorAmount(0, period, currentDate)}</h1>
                    <p>访客数</p>
                  </div>
                  <div class="col-xs-4">
                    <h1>${empty statistics ? '0' : statistics.experienceAmount + statistics.coachExperienceAmount}</h1>
                    <p>参与体验课人数</p>
                  </div>
                  <div class="col-xs-4">
                    <h1>${empty statistics ? '0' : statistics.conversion}%</h1>
                    <p>转化率</p>
                  </div>
                </div>
              </div>
             </c:if>
              
              <c:forEach var="currentSite" items="${empty selectSite ? (persist.getSites(currentPrincipal.id)) : selectSite.arraySite}">
                <h2 class="title">
                  <i class="glyphicon glyphicon-triangle-right" style="color: #FF8100;" title=""></i>&nbsp;&nbsp;<span>${currentSite.name}</span>
                </h2>
                
                <div style="margin: 0 15px;">
                  <div class="x-breadcrumb-content row key-data">
                    <div class="col-xs-4">
                      <h1>${persist.visitorAmount(currentSite.id, period, currentDate)}</h1>
                      <p>访客数</p>
                    </div>
                    <div class="col-xs-4">
                      <h1>${empty reports[currentSite.transferId] ? '0' : reports[currentSite.transferId].experienceAmount + reports[currentSite.transferId].coachExperienceAmount}</h1>
                      <p>参与体验课人数</p>
                    </div>
                    <div class="col-xs-4">
                      <h1>${empty reports[currentSite.transferId] ? '0.00' : reports[currentSite.transferId].conversion}%</h1>
                      <p>转化率</p>
                    </div>
                  </div>
                </div>
              </c:forEach>
               
             </div>
           </div>
          
        </div>

      </div>

    </div>

  </div>

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/report/visitor-report.js">
    <script type="text/javascript">
      require(['page/report/visitor-report'], function(page) {
        page.init({
            "date": '${day}',
            "site": '${selectSite.id}',
            "period": '${period}',
            "today": '${today}'
          })
      })
    </script>
  </d:resource>
  
</body>
</html>